﻿#ifndef DINGDANSERVICE_H
#define DINGDANSERVICE_H

#include <QObject>
#include "dingdan.h"
#include "dingdannetworkaccessmanager.h"
#include "dingdananddetail.h"
#include "historyproduct.h"
#include <QPushButton>

class DingdanService : public QObject
{
    Q_OBJECT
public:
    explicit DingdanService(QObject *parent = nullptr);

    void saveDingdan(QWidget *widget, Dingdan &dingdan);

    void deleteDingdan(QWidget *widget, Dingdan &dingdan);

    void getDingdans(QWidget *widget, Dingdan::DingdanType type, Dingdan::DingdanState state);

    void getDingdanDetails(QWidget *widget, QString dingdanId);

    void getDingdanDetails(QWidget *widget, Dingdan *dingdan);

    void getDingdanDetails(QWidget *widget, Dingdan::FinanceWidgetType type, QString targetUsername);

    void calculateDingdan(QWidget *widget, QPushButton *button, Dingdan &dingdan);

    void queryDingdan(
            QWidget *widget,
            int type,
            QString targetUsername,
            QString startDate,
            QString endDate);

    void queryDingdanDetail(
            QWidget *widget,
            int type,
            QString targetUsername,
            QString productId,
            QString startDate,
            QString endDate);

    QList<Dingdan*> queryDingdan(
            QList<Dingdan*> currentDingdans,
            UserRelation::RelationType widgetType,
            int ticketType,
            int moneyType);

    bool checkTicketAndMoneyValue(
            double ticket,
            double money,
            int ticketType,
            int moneyType);

    QList<DingdanAndDetail*> queryDingdanDetail(
            QList<DingdanAndDetail*> currentDetais,
            UserRelation::RelationType widgetType,
            int queryType,
            int resultType);

    void financeSubmit(
            QWidget *widget,
            QPushButton *button,
            Dingdan::FinanceWidgetType type,
            QString relatedMessageId,
            UserRelation *relation,
            double preSave,
            double totalFinanceGive,
            double totalFinanceMake,
            double totalFinanceNeed,
            QList<DingdanDetail*> details);

    void getHistoryProducts(
            QWidget *widget,
            int type,
            UserRelation *relation,
            Product *product);

    void getImportDingdans(QWidget *widget, Dingdan::DingdanState state);

    void getImportDingdanDetails(
            QWidget *widget,
            QString targetUsername,
            QString targetCompanyId,
            QString dingdanId,
            int type);
signals:
    void saveDingdanSuccess();

    void deleteDingdanSuccess();

    void getDingdansSuccess(QList<Dingdan*> dingdans);

    void getDingdanInfoSuccess(Dingdan *dingdan);

    void getDingdanDetailSuccess();

    void calculateDingdanSuccess();

    void queryDingdanSuccess(QList<Dingdan*> dingdans);

    void queryDingdanDetailSuccess(QList<DingdanAndDetail*> details);

    void getDingdanDetailByTypeSuccess(QList<DingdanAndDetail*> details);

    void financeSubmitSuccess();

    void getSaleHistoryProductsSuccess(QList<HistoryProduct*> historyProducts);

    void getPurchaseHistoryProductsSuccess(QList<HistoryProduct*> historyProducts);

    void getImportDingdanSuccess(QList<Dingdan*> dingdans);

    void getImportDingdanDetailSuccess(
            QList<DingdanDetail*> sourceDetails,
            QList<DingdanDetail*> targetDetails,
            QList<Product*> sourceProducts,
            QList<Product*> targetProducts);

public slots:

private:
    DingdanNetworkAccessManager *manager;
};

#endif // DINGDANSERVICE_H
